<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">
        
    </ui:define>

    <ui:define name="left">
       
    </ui:define>

    <ui:define name="right">
       
    </ui:define>

    <ui:define name="content">
        <style>
            .ui-state-highlight.ui-selected {
                color: blueviolet;
            }
        </style>
        <p:panel style="height: 250px">        
            <h:form id="viewPOForm">

                <p:ajaxStatus style="width: 16px;height: 16px;">
                    <f:facet name="start">
                        <h:graphicImage value="./../images/ajaxloading.gif"/>
                    </f:facet>
                    <f:facet name="complete">
                        <h:outputText value=""/>
                    </f:facet>
                </p:ajaxStatus>
                <p:messages />

                <h:panelGrid columns="3" cellpadding="10">
                    <h:outputLabel style="font-weight: bold" value="Enter PO Number: "/>
                    <h:outputLabel style="font-weight: bold" value="#{poManagerBean.purchaseOrder.poNumber}"/>
                    <p:commandButton update="viewPOForm" oncomplete="poDialog.show();" image="ui-icon ui-icon-search" />    
                </h:panelGrid>
                <p:commandButton id="button" value="Next" ajax="false" action="#{poManagerBean.populatePurchaseOrder}"/>

            </h:form>
        </p:panel>
        
        <p:dialog header="Search Purchase Order" widgetVar="poDialog" hideEffect="explode" height="600" width="800">
            <h:form id="poForm">
                <p:dataTable var="purchaseOrder" value="#{spoManagerBean.pos}"
                             emptyMessage="No Purchase Orders found with given criteria" selection="#{poManagerBean.purchaseOrder}" selectionMode="single" widgetVar="potbl">

                    <f:facet name="header">
                        <p:outputPanel>
                            <h:outputText value="Search all fields:" />
                            <p:inputText id="globalFilter" onkeyup="potbl.filter()" style="width:150px" />
                        </p:outputPanel>
                    </f:facet>

                    <p:column filterBy="#{purchaseOrder.poNumber}" 
                              headerText="PO Number" footerText="contains"
                              filterMatchMode="contains">
                        <h:outputText value="#{purchaseOrder.poNumber}" />
                    </p:column>

                    <p:column filterBy="#{purchaseOrder.customer.clientId}"
                              headerText="Client Id" footerText="contains">
                        <h:outputText value="#{purchaseOrder.customer.clientId}" />
                    </p:column>

                    <p:column filterBy="#{purchaseOrder.customer.companyName}"
                              headerText="Client Name" footerText="contains">
                        <h:outputText value="#{purchaseOrder.customer.companyName}" />
                    </p:column>

                    <p:column filterBy="#{purchaseOrder.customer.category}" 
                              headerText="Customer Category" footerText="exact"
                              filterOptions="#{scManagerBean.categoryOptions}"
                              filterMatchMode="exact">
                        <h:outputText value="#{purchaseOrder.customer.category}" />
                    </p:column>

                    <p:column filterBy="#{purchaseOrder.dateStr}" 
                              headerText="PO Date" footerText="contains"
                              filterMatchMode="contains">
                        <h:outputText value="#{purchaseOrder.dateStr}" />
                    </p:column>
                </p:dataTable>
                <p:commandButton value="Select Purchase Order" update="viewPOForm" oncomplete="poDialog.hide()"/>
            </h:form>
        </p:dialog>
    </ui:define>

    <ui:define name="bottom">
       
    </ui:define>

</ui:composition>
